<template>
	<view class="container">
		<view class="userinfo">
			<view>


				<view class="phone">{{userData.utell}}</view>
				<view>会员积分:0</view>
				<view>{{userData.urole}}</view>

			</view>

			<image src="/static/tx.jpg" mode="" @click="wd()"></image>
		</view>
		<view class="list">
			<view class="tab">
				<view v-for="(item,i) in navData" :class="currentIndex===i?'current':''" @click="changeIndex(i)">
					{{item}}
				</view>
			</view>
			<div class="item" v-for="item in orderData">
				<image :src="'http://47.96.80.123:8000/img/'+item.product[0].pimageurl" mode=""></image>
				<view>
					<view>下单时间:{{item.otime}}</view>
					<view>订单总额:￥{{item.oprice}}</view>
				</view>
			</div>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				navData: ["全部订单", "已收货", "未收货", "退订"],
				//点击切换
				currentIndex: 0,
				teaToken: "", //用户认证信息
				userData: {}, //用户信息
				orderData: [] //用户订单信息
			}
		},
		onShow() {
			uni.getStorage({
				key: "teaToken",
				success: (data) => {
					this.teaToken = data.data
					this.queryUserInfo(this.teaToken)
					this.queryOrder(this.teaToken)
				}
			})

		},
		methods: {
			changeIndex(index) {
				this.currentIndex = index
				var ostate = ""
				if (index === 0) {
					ostate = ""
				} else if (index === 1) {
					ostate = "1"
				} else if (index === 3) {
					ostate = "2"
				} else if (index == 2) {
					ostate = "0"
				}

				//发起请求 获取订单信息
				uni.request({
					url: "http://47.96.80.123:8000/order/queryOrder",
					data: {
						token: this.teaToken,
						ostate: ostate
					},
					success: (res) => {
						//获取用户订单数据
						this.orderData = res.data.data
					}
				})

			},
			queryUserInfo(token) {
				uni.request({
					url: "http://47.96.80.123:8000/user/queryUserInfo?token=" + token,
					success: (res) => {
						//获取用户数据
						this.userData = res.data.data
					}
				})
			},
			queryOrder(token) {
				uni.request({
					url: "http://47.96.80.123:8000/order/queryOrder",
					data: {
						token: this.teaToken,
						ostate: ""
					},
					success: (res) => {
						//获取用户订单数据
						this.orderData = res.data.data
					}
				})
			},
			wd() {
				uni.navigateTo({
					url: "/pages/zy/zy"
				})
			}
		}
	}
</script>

<style scoped>
	.userinfo {
		height: 260rpx;
		background: #ffa71a;
		padding: 50rpx 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.userinfo view {
		font-size: 22px;
		line-height: 55rpx;
		color: #999;
	}

	.userinfo image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
	}

	.userinfo .phone {
		color: #fff;
		font-weight: bold;
	}

	.list {
		padding: 30rpx;
		box-sizing: border-box;
		padding-bottom: 60px;
	}

	.tab {
		display: flex;
		justify-content: space-between;
		height: 70rpx;
		align-items: center;
	}


	.tab view {
		border-bottom: 1px solid #f5f5f5;
	}

	.tab .current {
		border-bottom: 1px solid #000;
	}

	.item {
		display: flex;
		padding: 15rpx;
		box-sizing: border-box;
		border-bottom: 1px solid #000;
		align-items: center;
	}

	.item image {
		width: 230rpx;
		height: 150rpx;
	}

	.item view {
		line-height: 50rpx;
	}

	.container {
		background: #f5f5f5;
	}
</style>